package com.hangkong.service.impl;//package com.heitian.hangkong.service.impl;

import com.hangkong.dao.passengerinfoMapper;
import com.hangkong.dao.torderMapper;
import com.hangkong.model.torder;
import com.hangkong.service.OrderService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.persistence.Id;
import java.sql.Timestamp;
import java.util.List;

/**
 * Created by Zhangxq on 2016/7/15.
 */

@Service
@Transactional(rollbackFor = Exception.class)
public class OrderServiceImpl implements OrderService {

    @Resource
    private torderMapper torderMapper;
    @Resource
    private passengerinfoMapper passengerinfoMapper;

    public List<torder> getAllOrder() {
        return torderMapper.selectAllOrder();
    }

    public int DeleteOrder(String id) {
        return torderMapper.deleteByPrimaryKey(id,1);
    }

    public int changeTkt(String tktid) {
        return torderMapper.changeTkt(tktid);
    }

    public torder queryOrderAll(String id) {
        String lid=id.substring(2);
        return torderMapper.queryOrderAll(lid);
    }

    public List<torder> condition_query(String flightno, String deptcity, String arrcity,
                                        String userid, String linkman, String linkphone,
                                        String flightdate) {
       if (flightno.equals("航班号")||flightno==""){flightno=null;}
       if (deptcity.equals("出发地")||deptcity==""){deptcity=null;}
       if (arrcity.equals("目的地")){arrcity=null;}
       if (userid.equals("用户ID")){userid=null;}
       if (linkman.equals("联系人")){linkman=null;}
       if (linkphone.equals("联系人手机号")){linkphone=null;}
       if (flightdate.equals("航班日期")){flightdate=null;}
        return torderMapper.condition_query(flightno,deptcity,arrcity,userid
                ,linkman,linkphone,flightdate);
    }

//    public torder insertOrder(String flightNo, String deptCity, String arrCity,
//                              String booking_linkInfo_name, String booking_linkInfo_phone,
//                              String flightCabin,  Timestamp flightDate_Dept_Date,Timestamp Create_Date) {
//
//        return torderMapper.insertOrder(flightNo,deptCity,arrCity,booking_linkInfo_name,
//                booking_linkInfo_phone,flightCabin,flightDate_Dept_Date,Create_Date);
//    }

    public Integer insertOrder(torder order) {
       return torderMapper.insertOrder(order);
    }

    public String selectId() {
        return torderMapper.selectId();
    }

    public torder showUserOrder(String id) {
        return torderMapper.selectByPrimaryKey(id);
    }

    public List<torder> passengInfo(String id) {
        return passengerinfoMapper.selectByOrderId(id);
    }

    public Integer insertPassenger(String s, String arrayZjlx, String s1, String orderId, Timestamp timeStamp) {
        return passengerinfoMapper.insertPassenger(s,arrayZjlx,s1,orderId,timeStamp);
    }

}
